package com.warmheart.core.result;

import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.warmheart.core.enums.ResultCode;
import com.warmheart.core.enums.WhEnum;
import com.warmheart.model.DictShow;

/**
 * 
 * @ClassName: CommonResult
 * @Description: 响应码为整数型的响应信息包装类，除接收的接口通知类等个别情况除外，对应响应信息应统一包装成该类型返回
 * @author ZhangJianyang
 * @date 2025-06-16 09:37:02
 *
 * @param <T>
 */
public class CommonResult<T> {

    private Integer code;

    private String message;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private T data;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Map<String, List<DictShow>> dictData;

    protected CommonResult() {
    }

    protected CommonResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    protected CommonResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 
     * @Title: success
     * @Description: 成功返回结果
     * @author ZhangJianyang
     * @return
     */
    public static <T> CommonResult<T> success() {
        return new CommonResult<T>(ResultCode.SUCCESS.getValue(), ResultCode.SUCCESS.getDesc());
    }

    /**
     * 
     * @Title: success
     * @Description: 成功返回结果
     * @author ZhangJianyang
     * @param data
     *            返回的数据
     * @return
     */
    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<T>(ResultCode.SUCCESS.getValue(), ResultCode.SUCCESS.getDesc(), data);
    }

    /**
     * 
     * @Title: success
     * @Description: 成功返回结果
     * @author ZhangJianyang
     * @param message
     *            自定义信息
     * @return
     */
    public static <T> CommonResult<T> success(String message) {
        return new CommonResult<T>(ResultCode.SUCCESS.getValue(), message);
    }

    /**
     * 
     * @Title: success
     * @Description: 成功返回结果
     * @author ZhangJianyang
     * @param message
     *            自定义信息
     * @param data
     *            返回数据
     * @return
     */
    public static <T> CommonResult<T> success(String message, T data) {
        return new CommonResult<T>(ResultCode.SUCCESS.getValue(), message, data);
    }

    /**
     * 失败返回结果
     */
    public static <T> CommonResult<T> failed() {
        return failed(ResultCode.FAILED);
    }

    /**
     * 失败返回结果
     * 
     * @param message
     *            提示信息
     */
    public static <T> CommonResult<T> failed(String message) {
        return new CommonResult<T>(ResultCode.FAILED.getValue(), message, null);
    }

    /**
     * 失败返回结果
     * 
     * @param errorCode
     *            错误码
     */
    public static <T> CommonResult<T> failed(WhEnum<Integer> whEnum) {
        return new CommonResult<T>(whEnum.getValue(), whEnum.getDesc(), null);
    }

    /**
     * 失败返回结果
     * 
     * @param errorCode
     *            错误码
     * @param message
     *            错误信息
     */
    public static <T> CommonResult<T> failed(WhEnum<Integer> whEnum, String message) {
        return new CommonResult<T>(whEnum.getValue(), message, null);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public Map<String, List<DictShow>> getDictData() {
        return dictData;
    }

    public CommonResult<T> putDictData(Map<String, List<DictShow>> dictData) {
        this.dictData = dictData;
        return this;
    }

}
